﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AjaxControlToolkit;


namespace Eassets.UI.Secure
{
    public partial class eSecureMaster : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session[Global.KeyLoginUserStakeholderId] != null)
            {
                // SecurityGroupScreenService securityGroupScreenService = new SecurityGroupScreenService();

                string frmName = "";
                int exsist = 0;
                frmName = Page.AppRelativeVirtualPath.Substring(8);
                frmName = frmName.Substring(0, frmName.LastIndexOf("."));
                //exsist = securityGroupScreenService.CheckExist(1,Convert.ToInt64(Session[Global.KeyLoginUserStakeholderId]),frmName,Convert.ToInt64(Session[Global.KeyCurrentCompanyId]));
                if (exsist == 0 && frmName != "EcorpHome")
                {
                    Response.Redirect("ReferenceHome.aspx");
                }
                else
                    Response.Redirect("ReferenceHome.aspx");
                //LoadNavigationMenu();
            }


            if (!IsPostBack)
            {
                try
                {
                    //LoadNavigationMenu();
                    if (Session["MyAccordion.SelectedIndex"] != null)
                    {
                        accordionModuleMenu.SelectedIndex = (int)Session["MyAccordion.SelectedIndex"];
                    }
                    if (Session["AccordionSubMenu.SelectedIndex"] != null && Session["SelectedSubMenuAccordionId"] != null)
                    {
                        ((Accordion)(accordionModuleMenu.FindControl(Session["SelectedSubMenuAccordionId"].ToString()))).SelectedIndex = (int)Session["AccordionSubMenu.SelectedIndex"];
                    }
                }
                catch (Exception exception)
                {
                    accordionModuleMenu.SelectedIndex = 0;
                    //((Accordion)((LinkButton)sender).Parent.Parent.Parent).SelectedIndex = -1;
                    //throw;
                }
            }

            String[] arrayTreePrograms = new string[1];
            arrayTreePrograms[0] = "ScreenForm.aspx";
            //arrayTreePrograms[1] = "FixedAssetForm.aspx";

            if (arrayTreePrograms.Contains(Page.Request.AppRelativeCurrentExecutionFilePath))
            {
                tabContainerMenuTree.ActiveTabIndex = 1;
            }
            else if (tabContainerMenuTree.Tabs.Count > 1)
            {
                tabContainerMenuTree.Tabs.RemoveAt(1);
            }
        }

        //protected void MenuLinkButton_OnClick(object sender, EventArgs e)
        //{
        //    Session["MyAccordion.SelectedIndex"] = accordionModuleMenu.SelectedIndex;
        //    Response.Redirect(((LinkButton)sender).CommandArgument);
        //}

        //protected void ScreenDetails_OnClick(object sender, EventArgs e)
        //{
        //    Response.Redirect("SecurityScreenForm.aspx");
        //}

        protected void SecurityGroups_OnClick(object sender, EventArgs e)
        {
            Response.Redirect("SecurityGroupForm.aspx");
        }

        protected void SecurityUserPermissionForm_OnClick(object sender, EventArgs e)
        {
            Response.Redirect("UserPermissionForm.aspx");
        }
    }
}